package com.greenant.store.adapter;

import java.util.ArrayList;

import com.greenant.store.R;
import com.greenant.store.bean.GoodsStyles;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class GoodsStylesAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<GoodsStyles> list = new ArrayList<GoodsStyles>();
	
	public static GoodsStylesAdapter newInstance(Context context,ArrayList<GoodsStyles> list)	{
		
		GoodsStylesAdapter adapter=new GoodsStylesAdapter();
		adapter.context = context;
		adapter.list = list;		
		return adapter;
	}	
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		GoodsStyles gStyles = list.get(position);
		H h = null;
		if(view==null){
			h = new H();
			view = LayoutInflater.from(context).inflate(R.layout.item_goods_style, parent, false);
			h.tvStyles = (TextView)view.findViewById(R.id.txStyle);
			h.tvCount = (TextView)view.findViewById(R.id.txCount);		
			view.setTag(h);
		}else{
			h = (H)view.getTag();
		}
		h.tvStyles.setText(gStyles.getStyles());
		h.tvCount.setText(gStyles.getCount());
		
		return view;
	}

	class H{
		TextView tvStyles;
		TextView tvCount;
	}
}
